package com.wake.mycomposebook.ui.home.layouts

import androidx.compose.foundation.layout.Column
import androidx.compose.material.ScrollableTabRow
import androidx.compose.material.Tab
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.wake.carousel.Pager
import com.wake.carousel.PagerState
import com.wake.mycomposebook.ui.home.layouts.advlist.AnimatedList
import com.wake.mycomposebook.ui.home.layouts.advlist.ShimmerList
import com.wake.mycomposebook.ui.home.layouts.advlist.SwipeableList
import com.wake.mycomposebook.utils.showLog

/**
 *@author created by WA03675
 *@date  2022-04-19 14:10
 *@des list动画
 *     q: 1.tab切换
 *        2.骨架
 *        3.list动画
 *        4.swipeable
 */


@Composable
fun MyAdvList() {
    MyTabsLayout()
}

@Composable
fun MyTabsLayout() {
    val tabs = listOf("Shimmers", "Animated Lists", "Swipe Lists")
    var selectIndex by remember {
        mutableStateOf(0)
    }

    val pageState: PagerState = run {
        remember {
            PagerState(0, 0, tabs.size - 1)
        }
    }
    Column {
        ScrollableTabRow(
            backgroundColor = androidx.compose.material3.MaterialTheme.colorScheme.surface,
            selectedTabIndex = selectIndex,
            edgePadding = 12.dp
        ) {
            tabs.forEachIndexed { index, title ->
                Tab(
                    selected = index == selectIndex,
                    onClick = {
                        selectIndex = tabs.indexOf(title)
                        pageState.currentPage = tabs.indexOf(title)
                    },
                    text = { Text(text = title) }
                )

            }
        }
        Pager(state = pageState, modifier = Modifier.weight(1f)) {

            selectIndex = pageState.currentPage
            showLog("aa ${selectIndex}")
            when (selectIndex) {
                0 -> {
                    ShimmerList()
                }
                1 -> {
                    AnimatedList()
                }
                2 -> {
                    SwipeableList()
                }
                else -> {}
            }

        }
    }
}
